package com.wanmait.movie.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wanmait.movie.entity.DTO.GenSeatMapDTO;
import com.wanmait.movie.entity.Seat;
import com.wanmait.movie.service.SeatService;
import com.wanmait.movie.util.AjaxResult;
import com.wanmait.movie.util.JWTUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * ClassName: ManageSeatControlle
 * Package: com.wanmait.movie.controller
 * Description:
 *
 * @Author Fengxd
 * @Create 2024/1/2 12:46
 * @Version 1.0
 */
@RestController
@RequestMapping("manage/seat")
public class ManageSeatController {
    @Resource
    private SeatService seatService;

//    @PostMapping("genSeatMap")
//    public AjaxResult genSeatMap(@RequestBody GenSeatMapDTO genSeatMapDTO, HttpServletRequest request) {
//        return AjaxResult.success(seatService.genSeatMap(genSeatMapDTO,request));
//    }

    @PostMapping("upSeatInfo")
    public AjaxResult upSeatInfo(@RequestBody GenSeatMapDTO genSeatMapDTO, HttpServletRequest request) {
        Integer currentAdminId = Integer.parseInt(JWTUtils.getAudience(request.getHeader("token")));
        List<Seat> seats = new ArrayList<>();
        genSeatMapDTO.getSeatDTOList().forEach(item -> {
            Seat seat = new Seat();
            BeanUtils.copyProperties(item,seat);
            seat.setUpdateAdminId(currentAdminId);
            seat.setUpdateTime(new Date());
            seats.add(seat);
        });
        return AjaxResult.success(seatService.updateBatchById(seats));
    }

    @GetMapping("getSeatInfo")
    public AjaxResult getSeatInfo(@RequestParam Integer id) {
        QueryWrapper<Seat> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("lobby_id",id);
        return AjaxResult.success(seatService.list(queryWrapper));
    }
}
